import fetch from '@/utils/network/fetch'

const getTransactions = (data, objc) => {
    data &&
        fetch('/api/trans_template', {
            ...objc,
            method: 'post',
            data
        })
}

const saveTransaction = (data, objc) => {
    data &&
        fetch('/api/trans_template', {
            ...objc,
            method: 'put',
            data
        })
}

const removeTransactions = (lIds, objc) => {
    lIds &&
        fetch('/api/trans_template/deletion', {
            ...objc,
            method: 'post',
            data: { lIds }
        })
}

const getEvidences = (data, objc) => {
    data &&
        fetch('/api/evidence_template', {
            ...objc,
            method: 'post',
            data
        })
}

const saveEvidence = (data, objc) => {
    data &&
        fetch('/api/evidence_template', {
            ...objc,
            method: 'put',
            data
        })
}

const removeEvidences = (lIds, objc) => {
    lIds &&
        fetch('/api/evidence_template/deletion', {
            ...objc,
            method: 'post',
            data: { lIds }
        })
}

const getEvidence = (id, objc) => {
    id &&
        fetch(`/api/evidence_template/${id}`, {
            ...objc,
            method: 'get'
        })
}
const getMedias = (type, data, objc) => {
    data &&
        type &&
        fetch(`/api/file/${type}`, {
            ...objc,
            method: 'post',
            data
        })
}

const saveMedia = (type, data, objc) => {
    data &&
        type &&
        fetch(`/api/file/${type}${data.id ? `/${data.id}` : ''}`, {
            ...objc,
            method: 'put',
            data
        })
}

const removeMedia = (type, fileId, objc) => {
    type &&
        fileId &&
        fetch(`/api/file/${type}/${fileId}`, {
            ...objc,
            method: 'delete'
        })
}

export default {
    // Transactions
    getTransactions,
    saveTransaction,
    removeTransactions,
    // Evidences
    getEvidence,
    getEvidences,
    saveEvidence,
    removeEvidences,
    // Media
    getMedias,
    saveMedia,
    removeMedia
}
